package com.ckd.flyingtrip.charge.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;
import com.ckd.flyingtrip.dialog.PayWayDialog;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/*
 * 支付信息
 * */
public class PaymentInformationActivity extends BaseActivity {

    @BindView(R.id.toolber_color_title)
    TextView title;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_volage)
    TextView tvVolage;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    private PayWayDialog.Builder pb;

    private String typeName;
    private String volageName;
    private String timeName;
    private String moneyName;
    private String costId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_information);
        ButterKnife.bind(this);

        initView();

    }


    private void initView() {
        title.setText("在线支付");

        Intent intent = getIntent();
        timeName = intent.getStringExtra("timeName");
        moneyName = intent.getStringExtra("moneyName");
        typeName = intent.getStringExtra("typeName");
        volageName = intent.getStringExtra("volageName");
        costId = intent.getStringExtra("costId");

        if ("0".equals(typeName)){
            tvType.setText("磷酸铁锂电池");
        }else if ("1".equals(typeName)){
            tvType.setText("铅酸电池");
        }else {
            tvType.setText("");
        }

        if ("1".equals(volageName)){
            tvVolage.setText("48V");
        }else if ("2".equals(volageName)){
            tvVolage.setText("60V");
        }else if ("3".equals(volageName)){
            tvVolage.setText("72V");
        }else {
            tvVolage.setText("");
        }

        if (null != timeName){
            tvTime.setText(timeName + "小时");
        }else {
            tvTime.setText("");
        }

        if (null != moneyName){
            tvMoney.setText("¥" + moneyName);
        }else {
            tvMoney.setText("");
        }
    }

    @OnClick({R.id.toolber_color_back, R.id.btn_pay})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.toolber_color_back:
                finish();
                break;
            case R.id.btn_pay:
                pb = new PayWayDialog.Builder(PaymentInformationActivity.this,
                        new PayWayDialog.Builder.PriorityListener() {
                            @Override
                            public void refreshPriorityUI(String f) {
                                volleyQueryFei(costId, f);
                                pb.create().dismiss();
                            }
                        });
                pb.create().show();
                break;
        }
    }

    private void volleyQueryFei(String id, String type) {
        if (type.equals("weixin")) {
//            Weixin weixin = new Weixin(GoumaiActivity.this, "");
//            weixin.volleyDINGDAN(id);
            dismisProgressDialog();
        } else if (type.equals("alipay")) {
            createLoadingDialog(this, "正在支付中...", true);
            ChargeAlipay alipay = new ChargeAlipay(PaymentInformationActivity.this, "", new ChargeAlipay.payInterface() {
                @Override
                public void paySuccess() {
                    //支付成功
                    Intent intent = new Intent();
                    setResult(1001, intent);
                    finish();
                }

                @Override
                public void payFail() {
                    //支付失败
                }
            });
            alipay.volleyChargePay(id,typeName, volageName, timeName);
        }
    }
}
